class ListNode {
  constructor(val, next) {
    this.val = (val===undefined ? 0 : val)
    this.next = (next===undefined ? null : next)
  }
}

const ArrayToListNode = function(array) {
  const root = new ListNode();
  let node = root
  let i = 0;
  while(i < array.length) {
    node.next = new ListNode(array[i]);
    node = node.next;
    ++i;
  }
  return root.next;
}

module.exports = {
  ListNode,
  ArrayToListNode
}